// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


// Adapted from Apache Arrow.

#pragma once

#include <arrow/result.h>
#include <pollux/dwio/parquet/writer/arrow/schema.h>

namespace arrow {
class DataType;
}

namespace kumo::pollux::parquet::arrow::arrow {

using ::arrow::Result;

Result<std::shared_ptr<::arrow::DataType>> FromByteArray(
    const LogicalType& logical_type);
Result<std::shared_ptr<::arrow::DataType>> FromFLBA(
    const LogicalType& logical_type,
    int32_t physical_length);
Result<std::shared_ptr<::arrow::DataType>> FromInt32(
    const LogicalType& logical_type);
Result<std::shared_ptr<::arrow::DataType>> FromInt64(
    const LogicalType& logical_type);

Result<std::shared_ptr<::arrow::DataType>> GetArrowType(
    Type::type physical_type,
    const LogicalType& logical_type,
    int type_length);

Result<std::shared_ptr<::arrow::DataType>> GetArrowType(
    Type::type physical_type,
    const LogicalType& logical_type,
    int type_length,
    ::arrow::TimeUnit::type int96_arrow_time_unit = ::arrow::TimeUnit::NANO);

Result<std::shared_ptr<::arrow::DataType>> GetArrowType(
    const schema::PrimitiveNode& primitive,
    ::arrow::TimeUnit::type int96_arrow_time_unit = ::arrow::TimeUnit::NANO);

} // namespace kumo::pollux::parquet::arrow::arrow
